<template>
	<el-main>
		<el-row :gutter="15">
			<el-col :xl="6" :lg="6" :md="8" :sm="12" :xs="24" v-for="item in list" :key="item.reportId">
				<el-card class="task task-item" shadow="hover">
					<h2 style="text-align: center">{{ item.title }}</h2>
					<ul>
						<li>
							<p class="info-title" :title="item.flowName"><span style="margin-right: 10px">相关公文:</span>{{ item.flowName }}</p>
						</li>
						<li>
							<p><span style="margin-right: 10px">创建时间:</span>{{ item.createTime }}</p>
						</li>
						<li>
							<h4>报表说明</h4>
							<div class="info-title" :title="item.remark">{{ item.remark }}</div>
						</li>
					</ul>
					<div class="bottom">
						<div class="state">
							<el-switch v-model="item.status" @change="changeSwitch($event, item)" active-text="启用" inactive-text="停用"
									   active-value="1" inactive-value="0"></el-switch>
						</div>
						<div class="handler">
							<el-dropdown trigger="click">
								<el-button type="primary" icon="el-icon-more" circle plain></el-button>
								<template #dropdown>
									<el-dropdown-menu>
										<el-dropdown-item @click="editRecord(item)">编辑</el-dropdown-item>
										<el-dropdown-item @click="deleteRecord(item)" divided>删除</el-dropdown-item>
									</el-dropdown-menu>
								</template>
							</el-dropdown>
						</div>
					</div>
				</el-card>
			</el-col>
			<el-col :xl="6" :lg="6" :md="8" :sm="12" :xs="24">
				<el-card class="task task-add" shadow="never" @click="add">
					<el-icon>
						<el-icon-plus/>
					</el-icon>
					<p>创建报表</p>
				</el-card>
			</el-col>
		</el-row>
	</el-main>
	<save v-if="dialog.save" ref="saveDialog" @success="getAllBpmReportList" @closed="dialog.save=false"></save>
</template>
<script>
import save from './save'
export default {
	name: 'Bpm Report Setting',
	components: {
		save,
	},
	data() {
		return {
			dialog:{
				save:false
			},
			list:[]
		}
	},
	mounted() {
		this.getAllBpmReportList();
	},
	methods: {
		//表格选择后回调事件
		async getAllBpmReportList(){
			var res = await this.$API.bpm.bpmReport.getAllBpmReportList.get({model:'1'});
			if (res.code == 200) {
				this.list=res.data;
			} else {
				this.$alert(res.message, "提示", {type: 'error'})
			}
		},
		async changeSwitch(val, item)
		{
			item.status = item.status == '1' ? '0' : '1'
			item.$switch_status = true;
			delete item.$switch_status;
			item.status = val;
			var res = await this.$API.bpm.bpmReport.updateBpmReport.post({reportId: item.reportId, status: item.status});
			if (res.code == 200) {
				//this.getAllBpmReportList();
				this.$message.success(res.message)
			} else {
				this.$alert(res.message, "提示", {type: 'error'})
			}
		},
		editRecord(item)
		{
			this.dialog.save = true
			this.$nextTick(() => {
				this.$refs.saveDialog.open('edit').setData(item)
			})
		},
		add() {
			this.dialog.save = true
			this.$nextTick(() => {
				this.$refs.saveDialog.open()
			})
		},
		async deleteRecord(reportItem)
		{
			var res = await this.$API.bpm.bpmReport.deleteBpmReport.post({reportId: reportItem.reportId});
			if (res.code == 200) {
				this.list.splice(this.list.findIndex(item => item.reportId === reportItem.reportId), 1)
				this.$message.success("删除成功")
			} else {
				this.$alert(res.message, "提示", {type: 'error'})
			}
		},
	},

}
</script>

<style scoped>
.task {
	height: 210px;
}

.task-item h2 {
	font-size: 15px;
	color: #3c4a54;
	padding-bottom: 15px;
}

.task-item li {
	list-style-type: none;
	margin-bottom: 10px;
}

.task-item li h4 {
	font-size: 12px;
	font-weight: normal;
	color: #999;
}

.task-item li p {
	margin-top: 5px;
}

.task-item .bottom {
	border-top: 1px solid #EBEEF5;
	text-align: right;
	padding-top: 10px;
	display: flex;
	justify-content: space-between;
	align-items: center;
}

.task-add {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	text-align: center;
	cursor: pointer;
	color: #999;
}

.task-add:hover {
	color: #409EFF;
}

.task-add i {
	font-size: 30px;
}

.task-add p {
	font-size: 12px;
	margin-top: 20px;
}

.dark .task-item .bottom {
	border-color: var(--el-border-color-light);
}

.info-title {
	width: 100%;
	overflow: hidden;
	white-space: nowrap;
	text-overflow: ellipsis;
	cursor: pointer;
}
</style>
